package com.beizhen.demo.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.beizhen.demo.entity.EntityPage;
import com.beizhen.demo.entity.StuTripPlan;
import com.beizhen.demo.entity.ZhuVo;
import com.beizhen.demo.service.StuTripPlanService;
import com.beizhen.demo.utils.PageResult;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.WebRequest;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
* 出行计划表 前端控制器
*/
@Controller
@RequestMapping("/stuTripPlan")
    public class StuTripPlanController {
    @Autowired
    private StuTripPlanService stuTripPlanService;

    /**
     * 出行管理---查询出行人数信息
     *
     */
    @RequestMapping("/te")
    public String te(Map<String,Object> map){
        String schoolUId="1";
        Integer people=stuTripPlanService.getPeople(schoolUId);
        Integer teahNum=stuTripPlanService.getTeacher(schoolUId);
        Integer baseCount=stuTripPlanService.getBid(schoolUId);
        Integer planNum=stuTripPlanService.getPlan(schoolUId);
        //查询总条数
        Integer count=stuTripPlanService.getcounts(Integer.parseInt(schoolUId));
        map.put("total",count);

        map.put("planNum",planNum);
        map.put("people",people);
        map.put("teahNum",teahNum);
        map.put("baseCount",baseCount);
        return "school/school_semester_studies_plan";
    }

    @RequestMapping("/getPage")
    @ResponseBody
    public PageResult<EntityPage> getPage(@RequestParam(required = false,defaultValue = "0") Integer currentpage){
        int schoolUId=1;
        //查询首页
        System.out.println(currentpage.getClass());
        PageResult<EntityPage> plan=stuTripPlanService.getPlanInfo(schoolUId,currentpage,2);
        System.out.println(plan.getRows());
        return plan;
    }
        @ResponseBody
        @RequestMapping("/getTotal")
        public Integer getTotal(){
            int schoolUId=1;
            //查询总条数
            Integer count=stuTripPlanService.getcounts(schoolUId);
            System.out.println(count);
            return count;
        }



    @RequestMapping("/getInfo")
    @ResponseBody
        public Map<String, Object> getInfo(){
        String schoolUId="1";
        Map<String,Object> map=new HashMap<>();
        List<ZhuVo> cylinder=stuTripPlanService.getCylinder(schoolUId);
        List<ZhuVo>  base=stuTripPlanService.Basegraphics(schoolUId);
        map.put("cylider",cylinder);
        map.put("base",base);
        System.out.println(map);
        return map;

    }
    //分页查询出行计划集合,   王佳乐
    @RequestMapping("/getStuTripPlanList/{DeclareStatus}")
    public String getStuTripPlanList(@PathVariable("DeclareStatus") Integer DeclareStatus){
        System.out.println("申报状态:"+DeclareStatus);
        //得到当前登录对象(学校对象)id
        Integer id=1001;
        QueryWrapper<StuTripPlan> wrapper=new QueryWrapper<StuTripPlan>();
        wrapper.eq("school_u_id",id).eq("tp_declare_status",DeclareStatus);
        //为PageHelper 设置当前页和展示条数
        PageHelper pageHelper=new PageHelper();
        pageHelper.startPage(2,1);
        PageInfo<StuTripPlan> stuTripPlanList=stuTripPlanService.getStuTripPlanList(pageHelper,wrapper);
        for(StuTripPlan stuTripPlan:stuTripPlanList.getList()){
            System.out.println("出行id:"+stuTripPlan.getTpId()+"出行学校:"+stuTripPlan.getSchoolUId()+"出行申报状态:"+stuTripPlan.getTpDeclareStatus());
        }
        return "ttt";
    }
	
	@RequestMapping("/goStuTripPlan")
    public String goStuTripPlan(){
        return "base_reception_program";
    }

    @RequestMapping("/selStuTripPlanById")//@RequestParam(value = "b_id") Integer b_id
    public String selStuTripPlanById(WebRequest webRequest){
        int b_id = 1;
        List<StuTripPlan> planList = stuTripPlanService.sel_StuTripPlan_Byid(b_id);
        webRequest.setAttribute("planList",planList, RequestAttributes.SCOPE_REQUEST);
        return "base_reception_program";
    }
}
